今天要來紀錄dplyr的集合運算函數
建立範例資料集
library(dplyr)
# 建立表格 x 和 y
x <- tribble(
~A, ~B, ~C,
"a", "t", 1,
"b", "u", 2,
"c", "v", 3
)
y <- tribble(
~A, ~B, ~C,
"b", "u", 2,
"c", "v", 4,
"d", "w", 5
)
# 找出兩個表格共有的列
result_intersect <- intersect(x, y)
print(result_intersect)
# 找出只存在於 x 的列
result_setdiff <- setdiff(x, y)
print(result_setdiff)
今天的小筆記先到這邊~
參考資料: